<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> - 登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-12">
                <form id="ajax_form" method="post" onsubmit="return false">
                    <h4 class="no-margins">登录：</h4>
                    <p class="m-t-md">登录到H+后台主题UI框架</p>
                    <input type="text" id="name" name="name" class="form-control uname" placeholder="用户名" />
                    <input type="password" id="password" name="password" class="form-control pword m-b" placeholder="密码" />
                  	<!--  验证码：<input type="text"name="checkCode" class="form-control pword m-b">
					<img id="codeImgId" src="/JavaWeb1907/checkImg" onclick="refreshCode()"><br/> -->
                    <a href="">忘记密码了？</a>
                    <button class="btn btn-success btn-block" onclick="submitForm()">登录</button>
                </form>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                &copy; hAdmin
            </div>
        </div>
    </div>
    <script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
    <script src="lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script src="lib/util.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	function submitForm() {
		console.log("submitForm");
		//1、验证用户名
		//1.1用户名不能为空
		//1.2格式是否合法，4-8位数字或字母
		/* var name = $("#name").val();
		var password = $("#password").val(); */
		var name = $("#name").val();
		var password = $("#password").val();
		//密码的验证
		//2.1密码不能为空
		//if(name == ""|| name == undefined || name == null){
			if(util.isEmpty(name)){
			mylayer.errorMsg("用户名不能为空");
			return;
		}
		if(util.isEmpty(password)){
		//if(password == ""|| password == undefined || password == null){
			mylayer.errorMsg("密码不能为空");
			return;
		}
		//2.2格式是否正确
		var pattern = /^[0-9a-zA-Z]{2,8}$/;
		if(pattern.test(password) == false){
		//if(!pattern.test(name)){
		mylayer.errorMsg("密码格式非法");	
		}
		var pattern = /^[0-9a-zA-Z]{2,8}$/;
		if(pattern.test(name) == false){
		//if(!pattern.test(name)){
		mylayer.errorMsg("账号格式非法");	
		}
		//ajax提交用户名和密码到后台验证是否存在，返回serverresponse
		//前台根据返回的serverresponse决定相应的操作
		//3.1code=success 登陆成功 mylayer.successurl跳转界面
		//3.2code=error 弹出失败信息 mylayer.error
		console.log($("#login_form").serialize());
		$.ajax({
		 url : "${pageContext.request.contextPath}/loginServlet?method=login",
		 type : "post",
		 dataType : "json",
		 data :$("#ajax_form").serialize(),
		 success : function(jsonObj){
				if(jsonObj.code == util.SUCCESS){
					mylayer.successMsgUrl(jsonObj.msg, "${pageContext.request.contextPath}/student?method=pageList");
					}else{
						mylayer.errorMsg("用户名或密码错误");		
					
				}
				
			}
		 
		});
		
	}
		
	
	
	
	
	
	
	
	
	</script>
	
</body>

</html>
